package com.deneme.ozveri.clicklisteners;

import java.util.ArrayList;

import android.app.Activity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;

import com.deneme.ozveri.adapters.MenuOrderListAdapter;
import com.deneme.ozveri.database.DBHandler;
import com.deneme.ozveri.objects.MenuItem;
import com.deneme.ozveri.objects.MenuOrderItem;
import com.deneme.ozverimenu.R;

public class SubItemOnClickListener implements OnItemClickListener {


	DBHandler dh;
	Activity act;
	ArrayList<MenuItem> subList;

	public SubItemOnClickListener(Activity actvt, DBHandler databaseHandler,ArrayList<MenuItem> subList) {
		dh = databaseHandler;
		act = actvt;
		this.subList = subList;
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		ArrayList<MenuOrderItem> orderItemList = dh.getOrderItems(subList.get(arg2).getMenuId());

		ListView orderList = (ListView) act.findViewById(R.id.menu_orderlist_listview);

		orderList.setAdapter(new MenuOrderListAdapter(orderItemList, act.getApplicationContext()));
		orderList.setOnItemClickListener( new OrderItemOnClickListener(act, dh, orderItemList));
		orderList.setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 60));
		orderList.setVisibility(View.VISIBLE);
		
		((LinearLayout)act.findViewById(R.id.menu_helper_linear)).setVisibility(View.GONE);

	}

}
